/**
 * [6] N 字形变换
 *
 * @format
 * @lc app=leetcode.cn id=6 lang=javascript
 */

// @lc code=start
/**
 * @param {string} s
 * @param {number} numRows
 * @return {string}
 */
var convert = function (s, numRows) {
    const matrix = new Array(numRows).fill(0).map(() => [])
    let [index, order] = [0, 0]
    while (index < s.length) {
        order = numRows === 1 ? 0 : index % (numRows + numRows - 2)
        order >= numRows ? (order = numRows + numRows - order - 2) : null
        matrix[order].push(s[index])
        index++
    }
    return matrix.reduce((p, c) => (p += c.join("")), "")
}
debugger
// let str = "PAYPALISHIRING"
let str = "A"
str = convert(str, 1)
console.log(str)
// @lc code=end
